 /**
 * @file otherCmds.c
 * @author MTF-1
 *
 * @date 22-01-2011 DD-MM-YYYY
 * @version 0.8
 *
 * @section DESCRIPTION
 *
 * Module for other commands.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tools.h"
#include "connectionCmds.h"
#include "otherCmds.h"

#define ERROR 1
#define NOERROR 0
#define AMOUNTOFCMD 6

/**
 * Exit the client program.
 *
 * @return exit status of the client program.
 * @author Rik Janssen
 */
int cmdExit()
{
    cmdDisconnect();
    printf("Will now exit...\n");
    exit(0);
}

/**
 * Show program information: version and creators.
 *
 * @return 0 on no error.
 * @author Rik Janssen, Robbert Busser
 */
int cmdInfo()
{
    printf("*********************************************\n"
           "*             MPNA 3RGK CLIENT              *\n"
           "*                                           *\n"
           "*Version 0.7 by Robbert Busser & Rik Janssen*\n"
           "*********************************************\n");

    return NOERROR;
}

/**
 * Shows global help and shows help for a specified command.
 *
 * @param *ptr_sCmd the specified command name.
 * @return 0 on no error and 1 on error (unknown command).
 * @author Robbert Busser
 */
int cmdHelp(char *ptr_sCmd)
{
    int iCmdNum = -1; /*Default is unknown command number*/

    /*Check if the command has been specified*/
    if(ptr_sCmd)
    {
        getCmdNum(ptr_sCmd, &iCmdNum);

        switch(iCmdNum)
        {
            case 0:
                printf("*****************************\n"
                       "*     MPNA 3RGK CLIENT      *\n"
                       "*                           *\n"
                       "*   Help for command exit   *\n"
                       "*                           *\n"
                       "*    Global information:    *\n"
                       "*  disconnects the current  *\n"
                       "*   client-server session   *\n"
                       "*  and closes the program.  *\n"
                       "*                           *\n"
                       "*  Technical information:   *\n"
                       "*  exit without parameter   *\n"
                       "*****************************\n");
                break;
            case 1:
                printf("*****************************\n"
                       "*     MPNA 3RGK CLIENT      *\n"
                       "*                           *\n"
                       "*  Help for command connect *\n"
                       "*                           *\n"
                       "*    Global information:    *\n"
                       "* creates the client-server *\n"
                       "*  connection/session with  *\n"
                       "*  the specificied IPv4     *\n"
                       "*  address and port number  *\n"
                       "*                           *\n"
                       "*  Technical information:   *\n"
                       "*  connect with parameter   *\n"
                       "server IPv4 address and port*\n"
                       "*****************************\n");
                break;
            case 2:
                printf("*****************************\n"
                       "*     MPNA 3RGK CLIENT      *\n"
                       "*                           *\n"
                       "*Help for command disconnect*\n"
                       "*                           *\n"
                       "*    Global information:    *\n"
                       "*  disconnects the current  *\n"
                       "*       client-server       *\n"
                       "*   connection/session      *\n"
                       "*                           *\n"
                       "*  Technical information:   *\n"
                       "*    disconnect without     *\n"
                       "*         parameter         *\n"
                       "*****************************\n");
                break;
            case 3:
                printf("*****************************\n"
                       "*     MPNA 3RGK CLIENT      *\n"
                       "*                           *\n"
                       "*  Help for command info    *\n"
                       "*                           *\n"
                       "*    Global information:    *\n"
                       "*     displays general      *\n"
                       "*    information about      *\n"
                       "*  the client program such  *\n"
                       "*  as version, autor, etc.  *\n"
                       "*                           *\n"
                       "*  Technical information:   *\n"
                       "*  info without parameter   *\n"
                       "*****************************\n");
                break;
            case 4:
                printf("*****************************\n"
                       "*     MPNA 3RGK CLIENT      *\n"
                       "*                           *\n"
                       "*  Help for command help    *\n"
                       "*                           *\n"
                       "*    Global information:    *\n"
                       "*    displays a list of     *\n"
                       "* commands were you can get *\n"
                       "* information about and if  *\n"
                       "* you need information about*\n"
                       "* one of those commands you *\n"
                       "* type that command behind  *\n"
                       "*   the help command help   *\n"
                       "*                           *\n"
                       "*  Technical information:   *\n"
                       "*  For general information  *\n"
                       "*   help without parameter  *\n"
                       "*                           *\n"
                       "*   For information about   *\n"
                       "*    one of the commands:   *\n"
                       "*   help with parameter of  *\n"
                       "*      specified command    *\n"
                       "*****************************\n");
                break;
            case 5:
                printf("*****************************\n"
                       "*     MPNA 3RGK CLIENT      *\n"
                       "*                           *\n"
                       "*  Help for command upload  *\n"
                       "*                           *\n"
                       "*    Global information:    *\n"
                       "* places the specified file *\n"
                       "*   from the client on the  *\n"
                       "* specified location on the *\n"
                       "*          server           *\n"
                       "*                           *\n"
                       "*  Technical information:   *\n"
                       "*  upload with parameter of *\n"
                       "* the name of the specified *\n"
                       "*   file on client + the    *\n"
                       "* name of specified file on *\n"
                       "*          the server       *\n"
                       "*****************************\n");
                break;
            case 6:
                printf("*****************************\n"
                       "*     MPNA 3RGK CLIENT      *\n"
                       "*                           *\n"
                       "* Help for command download *\n"
                       "*                           *\n"
                       "*    Global information:    *\n"
                       "* places the specified file *\n"
                       "*   from the server on the  *\n"
                       "* specified location on the *\n"
                       "*           client          *\n"
                       "*                           *\n"
                       "*  Technical information:   *\n"
                       "* download with parameter of*\n"
                       "*  the name of the file on  *\n"
                       "* the server + the parameter*\n"
                       "*  of specified file on the *\n"
                       "*           client          *\n"
                       "*****************************\n");
                break;
            case 7:
                printf("*****************************\n"
                       "*     MPNA 3RGK CLIENT      *\n"
                       "*                           *\n"
                       "*   Help for command list   *\n"
                       "*                           *\n"
                       "*    Global information:    *\n"
                       "*  displays the content of  *\n"
                       "*  the current directory on *\n"
                       "*         the server        *\n"
                       "*                           *\n"
                       "*  Technical information:   *\n"
                       "*  list without parameter   *\n"
                       "*****************************\n");
                break;
            case 8:
                printf("*****************************\n"
                       "*     MPNA 3RGK CLIENT      *\n"
                       "*                           *\n"
                       "*  Help for command remove  *\n"
                       "*                           *\n"
                       "*    Global information:    *\n"
                       "*   removes the specified   *\n"
                       "*   file from the current   *\n"
                       "*  directory on the server  *\n"
                       "*                           *\n"
                       "*  Technical information:   *\n"
                       "* remove with parameter the *\n"
                       "* specified name of file the*\n"
                       "*   on the server that you  *\n"
                       "*      want to remove       *\n"
                       "*****************************\n");
                break;
            case 9:
                printf("*****************************\n"
                       "*     MPNA 3RGK CLIENT      *\n"
                       "*                           *\n"
                       "*    Help for command cd    *\n"
                       "*                           *\n"
                       "*    Global information:    *\n"
                       "* changes the directory to  *\n"
                       "*  the specified directory  *\n"
                       "*        on the server      *\n"
                       "*                           *\n"
                       "*  Technical information:   *\n"
                       "* cd with parameter name of *\n"
                       "*  the specified directory  *\n"
                       "*      that you want to     *\n"
                       "*        change it to       *\n"
                       "*****************************\n");
                break;
            case 10:
                printf("*****************************\n"
                       "*     MPNA 3RGK CLIENT      *\n"
                       "*                           *\n"
                       "*  Help for command clear   *\n"
                       "*                           *\n"
                       "*    Global information:    *\n"
                       "*     clears the screen     *\n"
                       "*                           *\n"
                       "*  Technical information:   *\n"
                       "*  clear without parameter  *\n"
                       "*****************************\n");
                break;
            default:
                printf("Error: help for the specified command does not exist.\n");
                return ERROR; /*Unknown command*/
        }
    }
    else
    {
        /*No command has been specified -> show global help*/
        printf("*****************************\n"
               "*        3RGK CLIENT        *\n"
               "*                           *\n"
               "*       Help Function       *\n"
               "*       The commands:       *\n"
               "*           exit            *\n"
               "*          connect          *\n"
               "*         disconnect        *\n"
               "*           info            *\n"
               "*           help            *\n"
               "*          upload           *\n"
               "*         download          *\n"
               "*           list            *\n"
               "*          remove           *\n"
               "*            cd             *\n"
               "*           clear           *\n"
               "*****************************\n");
    }

    return NOERROR;
}

/**
 * Clears the screen.
 *
 * @return 1 on error and 0 on no error.
 * @author Robbert Busser
 */
int cmdClear()
{
    int i;

    for(i=0; i<50; i++)
    {
        printf("\n");
    }
    return NOERROR;
}
